MsgN("-- mdds_client.lua loaded")

MDDS.hidehud = false
MDDS.hiding = false

--custom hud to show enties life left
function MDDS.Hud()
	if (!MDDS.IsEnabled()) then return end

	--get player info
	local client = LocalPlayer()

	--if not alive then exit
	if !client:Alive() then return end

	local ent = client:GetEyeTrace().Entity

	--if (ValidEntity(ent) and EyePos():Distance(ent:GetPos()) > 512) then ent = nil end

	if (ValidEntity(ent)) then
		MDDS.hidehud = false
		MDDS.hiding = false
		MDDS.ent = ent
	else
		if (!MDDS.hiding) then
			MDDS.hiding = true
			timer.Simple(0.5, function()
				MDDS.hidehud = true
				MDDS.hiding = false
			end)
		end
	end

	if (!ValidEntity(MDDS.ent)) then return end

	--if entity not valid or weapon is camera, exit
	--if (!ValidEntity(ent) or client:GetActiveWeapon() == "Camera") then return end

	--try to get health
	local health = MDDS.ent:GetNWInt("Health")
	local maxhealth = MDDS.ent:GetNWInt("MaxHealth")

	--only show if needed
	--if (!MDDS.hidehud and (EyePos():Distance(MDDS.ent:GetPos()) < 512 or health == maxhealth)) then


	--get entity health
	local precentLeft = math.abs(100 - ((health / maxhealth) * 100))

	MD.MakeHud({
		{"Damage Info", "MDSBtip22", Color(255,255,0,255)},
		{{"Damage Taken:", tostring(math.ceil(precentLeft))}},
		{{"Current Health:", tostring(math.ceil(health))}},
		{{"Max Health:", tostring(math.ceil(maxhealth))}}
	},{
		name = "DamageHud",
		position = "Center Center",
		hide = MDDS.hidehud
	})
end

--add hud hook
hook.Add("HUDPaint", "MadDogs Damage System Hud", MDDS.Hud)